/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.thinkgem.jeesite.modules.order.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.modules.order.entity.FaHuoDan;
import com.thinkgem.jeesite.modules.order.dao.FaHuoDanDao;

/**
 * 发货单Service
 * @author 李忠
 * @version 2013-07-28
 */
@Component
@Transactional(readOnly = true)
public class FaHuoDanService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(FaHuoDanService.class);
	
	@Autowired
	private FaHuoDanDao faHuoDanDao;
	
	public FaHuoDan get(Long id) {
		return faHuoDanDao.findOne(id);
	}
	
	public Page<FaHuoDan> find(Page<FaHuoDan> page, FaHuoDan faHuoDan) {
		DetachedCriteria dc = faHuoDanDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(faHuoDan.getName())){
			dc.add(Restrictions.like("name", "%"+faHuoDan.getName()+"%"));
		}
		dc.add(Restrictions.eq(FaHuoDan.DEL_FLAG, FaHuoDan.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return faHuoDanDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(FaHuoDan faHuoDan) {
		faHuoDanDao.save(faHuoDan);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		faHuoDanDao.deleteById(id);
	}
	
}
